package com.bdbit.ChargingStation.Utils;


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

public class SHA1 {
    public  String getSHA1(String input) {
        try {
            MessageDigest sha1Digest = MessageDigest.getInstance("SHA-1");
            byte[] hashedBytes = sha1Digest.digest(input.getBytes());
            StringBuilder sb = new StringBuilder();
            for (byte b : hashedBytes) {
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
    public  int  getRandom(){
        Random random = new Random();
        int randomNumber = random.nextInt(9999) + 1000; // 生成一个[100000, 999999]之间的随机数
        return randomNumber;
    }

    public  String getKey(int nonce,long timestamp){
        String appSecret= "ek1DclwiXJ2";
        return getSHA1(appSecret+nonce+timestamp);
    }
}

